package com.inei.eea2014.model.dao;

import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.inei.eea2014.model.connection.UtilDB;
import com.inei.eea2014.model.entity.Capitulo4;

public class Capitulo4Dao implements ICRUD<Capitulo4> {

	// variables
	private UtilDB util;
	private SQLiteDatabase db;
	private Cursor cursor = null;

	// constructor
	public Capitulo4Dao(Context context) {
		util = new UtilDB(context);
	}

	// metodos del CRUD
	@Override
	public Capitulo4 buscar(Capitulo4 o) {
		Capitulo4 obj = null;
		db = util.getReadableDatabase();

		cursor = db.rawQuery(
				"select * from Capitulo4 where RUC=? and USUARIO=?",
				new String[] { o.getRUC() + "", o.getUSUARIO() + "" });
		if (cursor.moveToFirst()) {
			obj = new Capitulo4();
			obj.setRUC(cursor.getString(cursor.getColumnIndex("RUC")));
			obj.setUSUARIO(cursor.getString(cursor.getColumnIndex("USUARIO")));
			obj.setC0T01_001_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_001_01_T")));
			obj.setC0T01_001_02_T(cursor.getString(cursor
					.getColumnIndex("C0T01_001_02_T")));
			obj.setC0T01_002_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_002_01_T")));
			obj.setC0T01_003_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_003_01_T")));
			obj.setC0T01_003_02_T(cursor.getString(cursor
					.getColumnIndex("C0T01_003_02_T")));
			obj.setC0T01_004_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_004_01_T")));
			obj.setC0T01_005_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_005_01_T")));
			obj.setC0T01_005_02_T(cursor.getString(cursor
					.getColumnIndex("C0T01_005_02_T")));
			obj.setC0T01_006_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_006_01_T")));
			obj.setC0T01_007_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_007_01_T")));
			obj.setC0T01_007_02_T(cursor.getString(cursor
					.getColumnIndex("C0T01_007_02_T")));
			obj.setC0T01_008_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_008_01_T")));
			obj.setC0T01_009_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_009_01_T")));
			obj.setC0T01_009_02_T(cursor.getString(cursor
					.getColumnIndex("C0T01_009_02_T")));
			obj.setC0T01_010_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_010_01_T")));
			obj.setC0T01_011_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_011_01_T")));
			obj.setC0T01_011_02_T(cursor.getString(cursor
					.getColumnIndex("C0T01_011_02_T")));
			obj.setC0T01_012_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_012_01_T")));
			obj.setC0T01_012_02_T(cursor.getString(cursor
					.getColumnIndex("C0T01_012_02_T")));
			obj.setC0T01_013_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_013_01_T")));
			obj.setC0T01_014_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_014_01_T")));
			obj.setC0T01_015_01_T(cursor.getString(cursor
					.getColumnIndex("C0T01_015_01_T")));
			obj.setC0T02_001_01_T(cursor.getString(cursor
					.getColumnIndex("C0T02_001_01_T")));
			obj.setC0T02_002_01_T(cursor.getString(cursor
					.getColumnIndex("C0T02_002_01_T")));
			obj.setC0T02_002_02_T(cursor.getString(cursor
					.getColumnIndex("C0T02_002_02_T")));
			obj.setC0T02_003_01_T(cursor.getString(cursor
					.getColumnIndex("C0T02_003_01_T")));
			obj.setC0T02_003_02_T(cursor.getString(cursor
					.getColumnIndex("C0T02_003_02_T")));
			obj.setC0T02_004_01_T(cursor.getString(cursor
					.getColumnIndex("C0T02_004_01_T")));
			obj.setC0T02_005_01_T(cursor.getString(cursor
					.getColumnIndex("C0T02_005_01_T")));
			obj.setC0T02_006_01_T(cursor.getString(cursor
					.getColumnIndex("C0T02_006_01_T")));
			obj.setC0T02_007_01_T(cursor.getString(cursor
					.getColumnIndex("C0T02_007_01_T")));
			obj.setC0T02_007_02_T(cursor.getString(cursor
					.getColumnIndex("C0T02_007_02_T")));
			obj.setC0T02_008_01_T(cursor.getString(cursor
					.getColumnIndex("C0T02_008_01_T")));
			obj.setC0T02_009_01_T(cursor.getString(cursor
					.getColumnIndex("C0T02_009_01_T")));
			obj.setC0T02_010_01_T(cursor.getString(cursor
					.getColumnIndex("C0T02_010_01_T")));
			obj.setC0T02_011_01_T(cursor.getString(cursor
					.getColumnIndex("C0T02_011_01_T")));
			obj.setC0T03_001_01_T(cursor.getString(cursor
					.getColumnIndex("C0T03_001_01_T")));
			obj.setC0T03_001_02_T(cursor.getString(cursor
					.getColumnIndex("C0T03_001_02_T")));
			obj.setC0T03_004_01_T(cursor.getString(cursor
					.getColumnIndex("C0T03_004_01_T")));
			obj.setC0T03_004_02_T(cursor.getString(cursor
					.getColumnIndex("C0T03_004_02_T")));
			obj.setC0T03_004_03_T(cursor.getString(cursor
					.getColumnIndex("C0T03_004_03_T")));
			obj.setC0T03_004_04_T(cursor.getString(cursor
					.getColumnIndex("C0T03_004_04_T")));
			obj.setC0T03_004_05_T(cursor.getString(cursor
					.getColumnIndex("C0T03_004_05_T")));
			obj.setC0T03_004_06_T(cursor.getString(cursor
					.getColumnIndex("C0T03_004_06_T")));
			obj.setC0T03_004_07_T(cursor.getString(cursor
					.getColumnIndex("C0T03_004_07_T")));
			obj.setC0T03_004_08_T(cursor.getString(cursor
					.getColumnIndex("C0T03_004_08_T")));
			obj.setC0T03_005_01_T(cursor.getString(cursor
					.getColumnIndex("C0T03_005_01_T")));
			obj.setC0T03_006_01_T(cursor.getString(cursor
					.getColumnIndex("C0T03_006_01_T")));
			obj.setC0T03_006_02_T(cursor.getString(cursor
					.getColumnIndex("C0T03_006_02_T")));
			obj.setC0T03_006_03_T(cursor.getString(cursor
					.getColumnIndex("C0T03_006_03_T")));
			obj.setC0T03_006_04_T(cursor.getString(cursor
					.getColumnIndex("C0T03_006_04_T")));
			obj.setC0T03_006_05_T(cursor.getString(cursor
					.getColumnIndex("C0T03_006_05_T")));
			obj.setC0T03_006_06_T(cursor.getString(cursor
					.getColumnIndex("C0T03_006_06_T")));
			obj.setC0T03_006_07_T(cursor.getString(cursor
					.getColumnIndex("C0T03_006_07_T")));
			obj.setC0T03_006_08_T(cursor.getString(cursor
					.getColumnIndex("C0T03_006_08_T")));
			obj.setC0T03_006_09_T(cursor.getString(cursor
					.getColumnIndex("C0T03_006_09_T")));
			obj.setC0T03_006_10_T(cursor.getString(cursor
					.getColumnIndex("C0T03_006_10_T")));
			obj.setC0T03_007_01_T(cursor.getString(cursor
					.getColumnIndex("C0T03_007_01_T")));
			obj.setC0T03_008_01_T(cursor.getString(cursor
					.getColumnIndex("C0T03_008_01_T")));
			obj.setC0T04_001_01_T(cursor.getString(cursor
					.getColumnIndex("C0T04_001_01_T")));
			obj.setC0T04_001_02_T(cursor.getString(cursor
					.getColumnIndex("C0T04_001_02_T")));
			obj.setC0T04_002_01_T(cursor.getString(cursor
					.getColumnIndex("C0T04_002_01_T")));
			obj.setC0T04_002_02_T(cursor.getString(cursor
					.getColumnIndex("C0T04_002_02_T")));
			obj.setC0T04_003_01_T(cursor.getString(cursor
					.getColumnIndex("C0T04_003_01_T")));
			obj.setC0T04_003_02_T(cursor.getString(cursor
					.getColumnIndex("C0T04_003_02_T")));
			obj.setC0T04_004_01_T(cursor.getString(cursor
					.getColumnIndex("C0T04_004_01_T")));
			obj.setC0T04_004_02_T(cursor.getString(cursor
					.getColumnIndex("C0T04_004_02_T")));
			obj.setC0T04_005_01_T(cursor.getString(cursor
					.getColumnIndex("C0T04_005_01_T")));
			obj.setC0T04_005_02_T(cursor.getString(cursor
					.getColumnIndex("C0T04_005_02_T")));
		}

		Cerrar();
		return obj;
	}

	@Override
	public List<Capitulo4> leer() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int crear(Capitulo4 o) {
		int resultado = 0;
		db = util.getWritableDatabase();
		db.beginTransaction();

		ContentValues valores = new ContentValues();
		valores.put("RUC", o.getRUC());
		valores.put("USUARIO", o.getUSUARIO());
		valores.put("C0T01_001_01_T", o.getC0T01_001_01_T());
		valores.put("C0T01_001_02_T", o.getC0T01_001_02_T());
		valores.put("C0T01_002_01_T", o.getC0T01_002_01_T());
		valores.put("C0T01_003_01_T", o.getC0T01_003_01_T());
		valores.put("C0T01_003_02_T", o.getC0T01_003_02_T());
		valores.put("C0T01_004_01_T", o.getC0T01_004_01_T());
		valores.put("C0T01_005_01_T", o.getC0T01_005_01_T());
		valores.put("C0T01_005_02_T", o.getC0T01_005_02_T());
		valores.put("C0T01_006_01_T", o.getC0T01_006_01_T());
		valores.put("C0T01_007_01_T", o.getC0T01_007_01_T());
		valores.put("C0T01_007_02_T", o.getC0T01_007_02_T());
		valores.put("C0T01_008_01_T", o.getC0T01_008_01_T());
		valores.put("C0T01_009_01_T", o.getC0T01_009_01_T());
		valores.put("C0T01_009_02_T", o.getC0T01_009_02_T());
		valores.put("C0T01_010_01_T", o.getC0T01_010_01_T());
		valores.put("C0T01_011_01_T", o.getC0T01_011_01_T());
		valores.put("C0T01_011_02_T", o.getC0T01_011_02_T());
		valores.put("C0T01_012_01_T", o.getC0T01_012_01_T());
		valores.put("C0T01_012_02_T", o.getC0T01_012_02_T());
		valores.put("C0T01_013_01_T", o.getC0T01_013_01_T());
		valores.put("C0T01_014_01_T", o.getC0T01_014_01_T());
		valores.put("C0T01_015_01_T", o.getC0T01_015_01_T());
		valores.put("C0T02_001_01_T", o.getC0T02_001_01_T());
		valores.put("C0T02_002_01_T", o.getC0T02_002_01_T());
		valores.put("C0T02_002_02_T", o.getC0T02_002_02_T());
		valores.put("C0T02_003_01_T", o.getC0T02_003_01_T());
		valores.put("C0T02_003_02_T", o.getC0T02_003_02_T());
		valores.put("C0T02_004_01_T", o.getC0T02_004_01_T());
		valores.put("C0T02_005_01_T", o.getC0T02_005_01_T());
		valores.put("C0T02_006_01_T", o.getC0T02_006_01_T());
		valores.put("C0T02_007_01_T", o.getC0T02_007_01_T());
		valores.put("C0T02_007_02_T", o.getC0T02_007_02_T());
		valores.put("C0T02_008_01_T", o.getC0T02_008_01_T());
		valores.put("C0T02_009_01_T", o.getC0T02_009_01_T());
		valores.put("C0T02_010_01_T", o.getC0T02_010_01_T());
		valores.put("C0T02_011_01_T", o.getC0T02_011_01_T());
		valores.put("C0T03_001_01_T", o.getC0T03_001_01_T());
		valores.put("C0T03_001_02_T", o.getC0T03_001_02_T());
		valores.put("C0T03_004_01_T", o.getC0T03_004_01_T());
		valores.put("C0T03_004_02_T", o.getC0T03_004_02_T());
		valores.put("C0T03_004_03_T", o.getC0T03_004_03_T());
		valores.put("C0T03_004_04_T", o.getC0T03_004_04_T());
		valores.put("C0T03_004_05_T", o.getC0T03_004_05_T());
		valores.put("C0T03_004_06_T", o.getC0T03_004_06_T());
		valores.put("C0T03_004_07_T", o.getC0T03_004_07_T());
		valores.put("C0T03_004_08_T", o.getC0T03_004_08_T());
		valores.put("C0T03_005_01_T", o.getC0T03_005_01_T());
		valores.put("C0T03_006_01_T", o.getC0T03_006_01_T());
		valores.put("C0T03_006_02_T", o.getC0T03_006_02_T());
		valores.put("C0T03_006_03_T", o.getC0T03_006_03_T());
		valores.put("C0T03_006_04_T", o.getC0T03_006_04_T());
		valores.put("C0T03_006_05_T", o.getC0T03_006_05_T());
		valores.put("C0T03_006_06_T", o.getC0T03_006_06_T());
		valores.put("C0T03_006_07_T", o.getC0T03_006_07_T());
		valores.put("C0T03_006_08_T", o.getC0T03_006_08_T());
		valores.put("C0T03_006_09_T", o.getC0T03_006_09_T());
		valores.put("C0T03_006_10_T", o.getC0T03_006_10_T());
		valores.put("C0T03_007_01_T", o.getC0T03_007_01_T());
		valores.put("C0T03_008_01_T", o.getC0T03_008_01_T());
		valores.put("C0T04_001_01_T", o.getC0T04_001_01_T());
		valores.put("C0T04_001_02_T", o.getC0T04_001_02_T());
		valores.put("C0T04_002_01_T", o.getC0T04_002_01_T());
		valores.put("C0T04_002_02_T", o.getC0T04_002_02_T());
		valores.put("C0T04_003_01_T", o.getC0T04_003_01_T());
		valores.put("C0T04_003_02_T", o.getC0T04_003_02_T());
		valores.put("C0T04_004_01_T", o.getC0T04_004_01_T());
		valores.put("C0T04_004_02_T", o.getC0T04_004_02_T());
		valores.put("C0T04_005_01_T", o.getC0T04_005_01_T());
		valores.put("C0T04_005_02_T", o.getC0T04_005_02_T());

		resultado = (int) db.insert("Capitulo4", null, valores);
		if (resultado > 0) {
			db.setTransactionSuccessful();
		}

		valores.clear();
		Cerrar();
		return resultado;
	}

	@Override
	public int actualizar(Capitulo4 o) {
		int resultado = 0;
		db = util.getWritableDatabase();
		db.beginTransaction();

		ContentValues valores = new ContentValues();
		valores.put("C0T01_001_01_T", o.getC0T01_001_01_T());
		valores.put("C0T01_001_02_T", o.getC0T01_001_02_T());
		valores.put("C0T01_002_01_T", o.getC0T01_002_01_T());
		valores.put("C0T01_003_01_T", o.getC0T01_003_01_T());
		valores.put("C0T01_003_02_T", o.getC0T01_003_02_T());
		valores.put("C0T01_004_01_T", o.getC0T01_004_01_T());
		valores.put("C0T01_005_01_T", o.getC0T01_005_01_T());
		valores.put("C0T01_005_02_T", o.getC0T01_005_02_T());
		valores.put("C0T01_006_01_T", o.getC0T01_006_01_T());
		valores.put("C0T01_007_01_T", o.getC0T01_007_01_T());
		valores.put("C0T01_007_02_T", o.getC0T01_007_02_T());
		valores.put("C0T01_008_01_T", o.getC0T01_008_01_T());
		valores.put("C0T01_009_01_T", o.getC0T01_009_01_T());
		valores.put("C0T01_009_02_T", o.getC0T01_009_02_T());
		valores.put("C0T01_010_01_T", o.getC0T01_010_01_T());
		valores.put("C0T01_011_01_T", o.getC0T01_011_01_T());
		valores.put("C0T01_011_02_T", o.getC0T01_011_02_T());
		valores.put("C0T01_012_01_T", o.getC0T01_012_01_T());
		valores.put("C0T01_012_02_T", o.getC0T01_012_02_T());
		valores.put("C0T01_013_01_T", o.getC0T01_013_01_T());
		valores.put("C0T01_014_01_T", o.getC0T01_014_01_T());
		valores.put("C0T01_015_01_T", o.getC0T01_015_01_T());
		valores.put("C0T02_001_01_T", o.getC0T02_001_01_T());
		valores.put("C0T02_002_01_T", o.getC0T02_002_01_T());
		valores.put("C0T02_002_02_T", o.getC0T02_002_02_T());
		valores.put("C0T02_003_01_T", o.getC0T02_003_01_T());
		valores.put("C0T02_003_02_T", o.getC0T02_003_02_T());
		valores.put("C0T02_004_01_T", o.getC0T02_004_01_T());
		valores.put("C0T02_005_01_T", o.getC0T02_005_01_T());
		valores.put("C0T02_006_01_T", o.getC0T02_006_01_T());
		valores.put("C0T02_007_01_T", o.getC0T02_007_01_T());
		valores.put("C0T02_007_02_T", o.getC0T02_007_02_T());
		valores.put("C0T02_008_01_T", o.getC0T02_008_01_T());
		valores.put("C0T02_009_01_T", o.getC0T02_009_01_T());
		valores.put("C0T02_010_01_T", o.getC0T02_010_01_T());
		valores.put("C0T02_011_01_T", o.getC0T02_011_01_T());
		valores.put("C0T03_001_01_T", o.getC0T03_001_01_T());
		valores.put("C0T03_001_02_T", o.getC0T03_001_02_T());
		valores.put("C0T03_004_01_T", o.getC0T03_004_01_T());
		valores.put("C0T03_004_02_T", o.getC0T03_004_02_T());
		valores.put("C0T03_004_03_T", o.getC0T03_004_03_T());
		valores.put("C0T03_004_04_T", o.getC0T03_004_04_T());
		valores.put("C0T03_004_05_T", o.getC0T03_004_05_T());
		valores.put("C0T03_004_06_T", o.getC0T03_004_06_T());
		valores.put("C0T03_004_07_T", o.getC0T03_004_07_T());
		valores.put("C0T03_004_08_T", o.getC0T03_004_08_T());
		valores.put("C0T03_005_01_T", o.getC0T03_005_01_T());
		valores.put("C0T03_006_01_T", o.getC0T03_006_01_T());
		valores.put("C0T03_006_02_T", o.getC0T03_006_02_T());
		valores.put("C0T03_006_03_T", o.getC0T03_006_03_T());
		valores.put("C0T03_006_04_T", o.getC0T03_006_04_T());
		valores.put("C0T03_006_05_T", o.getC0T03_006_05_T());
		valores.put("C0T03_006_06_T", o.getC0T03_006_06_T());
		valores.put("C0T03_006_07_T", o.getC0T03_006_07_T());
		valores.put("C0T03_006_08_T", o.getC0T03_006_08_T());
		valores.put("C0T03_006_09_T", o.getC0T03_006_09_T());
		valores.put("C0T03_006_10_T", o.getC0T03_006_10_T());
		valores.put("C0T03_007_01_T", o.getC0T03_007_01_T());
		valores.put("C0T03_008_01_T", o.getC0T03_008_01_T());
		valores.put("C0T04_001_01_T", o.getC0T04_001_01_T());
		valores.put("C0T04_001_02_T", o.getC0T04_001_02_T());
		valores.put("C0T04_002_01_T", o.getC0T04_002_01_T());
		valores.put("C0T04_002_02_T", o.getC0T04_002_02_T());
		valores.put("C0T04_003_01_T", o.getC0T04_003_01_T());
		valores.put("C0T04_003_02_T", o.getC0T04_003_02_T());
		valores.put("C0T04_004_01_T", o.getC0T04_004_01_T());
		valores.put("C0T04_004_02_T", o.getC0T04_004_02_T());
		valores.put("C0T04_005_01_T", o.getC0T04_005_01_T());
		valores.put("C0T04_005_02_T", o.getC0T04_005_02_T());

		resultado = (int) db.update("Capitulo4", valores,
				"RUC=? and USUARIO=?",
				new String[] { o.getRUC() + "", o.getUSUARIO() + "" });
		if (resultado > 0) {
			db.setTransactionSuccessful();
		}

		valores.clear();
		Cerrar();
		return resultado;
	}

	@Override
	public int eliminar(Capitulo4 o) {
		// TODO Auto-generated method stub
		return 0;
	}

	// otros metodos
	private void Cerrar() {
		if (cursor != null) {
			cursor.close();
		}
		if (db.inTransaction()) {
			db.endTransaction();
		}
		if (db.isOpen()) {
			db.close();
		}
	}
}
